package com.woniuxy.service.impl;

import com.woniuxy.dao.ProductDao;
import com.woniuxy.entity.Product;
import com.woniuxy.entity.utils.ResponseEntity;
import com.woniuxy.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;
import java.util.Optional;

/**
 * @Author: 马宇航
 * @Do: Product 商品实现类
 * @DateTime: 22/06/21/0021 下午 2:59
 * @Component: 成都蜗牛学苑
 **/
@Service
public class ProductServiceImpl implements ProductService {
    @Autowired
    ProductDao productDao;
    @Override
    public Product addOne(Product product) {
        Product save = productDao.save(product);
        return save;
    }

    @Override
    public ResponseEntity findOneById(Integer id) {
        Optional<Product> product = productDao.findById(id);
        //product != null 进行判空
        if (product.isPresent()) {
            return new ResponseEntity(product.get());
        }
        return ResponseEntity.ERROR;
    }

    @Override
    public List<Product> search1(Integer minimumInventory, Integer maxInventory) {
        return  productDao.findAllByStockBetween(minimumInventory,maxInventory);
    }

}
